# -*- encoding: utf-8 -*-
"""
Some extra plugins, a few different plugins merged together
"""
import os, subprocess, sys
from setuptools import setup
from distutils.core import Extension

os.chdir(os.path.dirname(os.path.abspath(__file__)))

__author__ = "Szentandrási István"

LANGUAGES = ('zh_CN', 'ca')
DOMAIN = 'extras'
BASEDIR = DOMAIN+os.path.sep
PACKAGES = ['extras', 
    'extras.lyrics', 'extras.lyrics.modules',
    'extras.albumart', 'extras.albumart.modules']

#generate templates
if '--gen_templates' in sys.argv:
    os.system("pygettext.py -d %s -p %s %s" % 
            (DOMAIN, BASEDIR+"po", 
                "/*.py ".join([a.replace('.', '/') for a in PACKAGES])+"/*.py" )
            )
    sys.argv.remove('--gen_templates')

# Create mo files:
if not os.path.exists(BASEDIR+"locale"):
        os.mkdir(BASEDIR+"locale/")
for lang in LANGUAGES:
        pofile = BASEDIR+"po/" + lang + ".po"
        mofile = BASEDIR +"locale/"+ lang + "/"+DOMAIN+".mo"
        if not os.path.exists(BASEDIR+"locale/" + lang + "/"):
                os.mkdir(BASEDIR+"locale/" + lang + "/")
        print "generating", mofile
        os.system("msgfmt %s -o %s" % (pofile, mofile))

def capture(cmd):
    pipe = subprocess.Popen(cmd, shell =True, stdout= subprocess.PIPE).stdout
    retval = pipe.read().strip()
    pipe.close()
    return retval

setup(
        name = "Extras Pack",
        version = "0.1",
        description = __doc__,
        author = __author__,
        packages = PACKAGES,
        ext_modules=[Extension("extras.mmkeys", ["extras/mmkeys/mmkeyspy.c", "extras/mmkeys/mmkeys.c", "extras/mmkeys/mmkeysmodule.c"],
            extra_compile_args=capture("pkg-config --cflags gtk+-2.0 pygtk-2.0").split(),
            extra_link_args=capture("pkg-config --libs gtk+-2.0 pygtk-2.0").split()
            ),],
        include_package_data = True,
        package_data = { 'extras': ['locale/*/*.mo']},
        entry_points = '''
        [etude.extra]
        MediaButtons = extras.mbuttons:MediaButtons
        LyricsQuerier = extras.lyrics.querier:Querier
        AlbumArtQuerier = extras.albumart.querier:Querier
        AudioScrobbler = extras.scrobbler:AudioScrobbler
        DBusPlugin = extras.dbus_plugin:DBusPlugin
        GnomeMediaButtons = extras.gnome_mbuttons:GnomeMediaButtons
        '''
        )

